/*
	conditionLanguage/parser.h
	@author:Wolfhead
*/
#ifndef WOLV_CONDITION_LANGUAGE_PARSER_H
#define WOLV_CONDITION_LANGUAGE_PARSER_H

#include "script.h"
#include "variable.h"

namespace wolv
{
namespace condition
{

class Parser
{
public:
	Parser();
	~Parser();

	/*
		Parse str into script
		@return int, 0 on success, other on failure
	*/
	int Parse(const std::string& str, Script& script);
	/*
		return the last error, produced by Parse
		@return int
	*/
	int GetLastError(){return errorCode_;};
	/*
		return the last error message, produced by Parse
		return std::string
	*/
	std::string GetLastErrorMessage(){return errorMessage_;};

private:
	std::string _getWord(const char*& start, bool readLineBreak = false);

	Variable _parseVaribale(const char*& start);
	int _parseOperation(const char*& start);
	std::string _parseAction(const char*& start);
	std::string _parseName(const char*& start);
	void _parseBreak(const char*& start);

	char _escape(char escape);

	void _setError(int code, const std::string& message ,const char * near);
	void _clearError();

	std::string errorMessage_;
	int errorCode_;
	int lastVarType;
	int currentLine_;
};



}
}





#endif

